今天把dialogfragment也搭配上bindnig然後試著把dialog的動作移到dialogviewmodel之中
class FragmentDialog: DialogFragment() {
private val viewModel: DialogViewModel<MainDialogResult> by activityViewModels()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding = DialogfragmentBinding.inflate(inflater,container,false)
binding.login.setOnClickListener {
val message = "ok"
viewModel.result.postValue(MainDialogResult.Ok(message))
dismiss()
}
binding.cancel.setOnClickListener {
viewModel.result.postValue(MainDialogResult.Cancel)
dismiss()
}
binding.progressBar.visibility = View.VISIBLE
binding.progressBar2.max = 100
Thread{
for (i in 0..100){
binding.progressBar2.progress = i
//Thread.sleep(500)
SystemClock.sleep(500)
}
}.start()
binding.progressBar2.progress = 0
return binding.root
}
}
這邊是還沒移過去的樣子,雖然目前架構還不完整,但是使用databinding之後畫面乾淨很多,dialog的viewmodel還在研究當中